<ul class="breadcrumb">
	<li><a href="{$BASE_PATH}admin/perfil">Perfil - {$perfil->getDsNome()}</a></li>
	<li>Vincular Ação</li>
</ul>

<form method='post' action='{$BASE_PATH}' class='validate sideBySide'>
	{$form->getElement('application')->render()}
	{$form->getElement('controller')->render()}
	{$form->getElement('method')->render()}
	{$form->getElement('perfil[version]')->render()}
	{$form->getElement('perfil[id_perfil]')->render()}
	<div class="control-group">
		{$form->getElement('perfil[aplicacao]')->getLabel()->render()}
		<div class="controls">
			{$form->getElement('perfil[aplicacao]')->render()}
		</div>
	</div>
	<div class="control-group">
		{$form->getElement('perfil[ds_controller]')->getLabel()->render()}
		<div class="controls">
			{$form->getElement('perfil[ds_controller]')->render()}
		</div>
	</div>
	<div class="control-group">
		{$form->getElement('perfil[ds_method]')->getLabel()->render()}
		<div class="controls">
			{$form->getElement('perfil[ds_method]')->render()}
		</div>
	</div>
	<div class="boxActions">
		{$form->getElement('salvar')->render()}
	</div>
</form>

<table id='dataTablePerfil' class="tableList">
	<thead>
		<tr>
			<th></th>
			<th><a href='#'>Perfil</a></th>
			<th><a href='#'>Aplicação</a></th>
			<th><a href='#'>Especialidade</a></th>
			<th><a href='#'>Ação</a></th>
		</tr>
	</thead>
	<tbody>
		{foreach from=$perfil->getAcoes() key=k item=i}
		<tr>
			<td><a href="{$BASE_PATH}admin/perfil/deletePermissao/id/{$i->getId()}" class="ico-delete"></a></td>
			<td>{$i->getPerfil()->getDsNome()}</td>
			<td>{$i->getAplicacao()->getDsNome()}</td>
			<td>{$i->getDsController()}</td>
			<td>{$i->getDsMethod()}</td>
		</tr>
		{/foreach}
	</tbody>
</table>
{literal}
	<script type="text/javascript">
		$(document).ready(function() {
			$('#id_perfil_aplicacao').change(function(){
				$.getJSON(BASE_PATH+'admin/aplicacao/returnController/id/'+this.value)
				.success(function(data){
					$("#id_perfil_ds_controller option").remove();
					$("#id_perfil_ds_controller").append($("<option />").val(null).text('-- Selecione --'));

					$("#id_perfil_ds_method option").remove();
					$("#id_perfil_ds_method").append($("<option />").val(null).text('-- Selecione --'));

					$.each(data, function(key,value) {
						$("#id_perfil_ds_controller").append($("<option />").val(key).text(value));
					});
				});
			});

			$('#id_perfil_ds_controller').change(function(){
				$.getJSON(BASE_PATH+'admin/aplicacao/returnMethod/idaplicacao/'+$('#id_perfil_aplicacao').val()+'/ds_controller/'+this.value)
				.success(function(data){
					$("#id_perfil_ds_method option").remove();
					$("#id_perfil_ds_method").append($("<option />").val(null).text('-- Selecione --'));

					$.each(data, function(key,value) {
						$("#id_perfil_ds_method").append($("<option />").val(key).text(value));
					});
				});
			});
		})
	</script>
{/literal}